package in.abip.chisame.model;

import in.abip.chisame.R;

/**
 * Camera record.
 * 
 * @author Julot.
 * @since Wednesday, January 26th, 2011. 
 */
public class Camera extends CActiveRecord implements IListItem {
	public Integer roomId = null;
	public String name = null;
	public String url = null;
	public String username = null;
	public String password = null;
	public String ipAddress = null;
	public Integer channel = null;
	
	public static Camera model() {
		return new Camera();
	}
	
	/** Implementation of IListItem interface */
	public int getListIconResource() {
		return R.drawable.ic_list_camera;
	}
	
	/** Implementation of IListItem interface */
	public String getListText() {
		return ((name == null) || (name.equals(""))) ? "Camera" : name;
	}
	
	protected Boolean beforeSave() {
		StringBuilder sb = new StringBuilder();
		sb.append("http://");
		sb.append(this.ipAddress);
		sb.append("/cgi-bin/guest/Video.cgi?media=mjpeg&channel=");
		sb.append(this.channel.toString());
		this.url = sb.toString();
		return true;
	}
}
